﻿using System;
using fastCSharp;
using fastCSharp.code.cSharp;

namespace diantou.web.topic
{
    /// <summary>
    /// 话题首页
    /// </summary>
    partial class index<viewType> : view<viewType>
        where viewType : index<viewType>
    {
        /// <summary>
        /// 问题集合
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        protected question.userQuestion[] questions;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        protected void loadQuestion(int page)
        {
            diantou.dataAccess.question[] questionArray = diantou.dataAccess.clientCache.Question.Get(diantou.dataAccess.tcpCall.topic.getQuestionIds(topic.Id, pageInfo.Size = fastCSharp.config.pub.Default.PageSize, pageInfo.Page = page, out pageInfo.Count));
            questions = questionArray.getArray(value => new question.userQuestion { Question = value, UserId = currentUserId });
            if (requestHeader.IsSearchEngine) pageInfo.Path = topic.Path.Index.ToPageString();
        }
    }
    /// <summary>
    /// 话题首页
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsReferer = false)]
    partial class index : index<index>
    {
        /// <summary>
        /// 话题首页
        /// </summary>
        /// <param name="topicId">话题标识</param>
        /// <param name="page">分页号</param>
        /// <returns>是否成功</returns>
        private bool loadView(idName topicId, int page)
        {
            if (base.load(ref topicId, getSearchPathHandle))
            {
                loadQuestion(page);
                return true;
            }
            return false;
        }
        /// <summary>
        /// 获取搜索路径
        /// </summary>
        private static Func<string, webView.hashUrl> getSearchPathHandle = getSearchPath;
        /// <summary>
        /// 获取搜索路径
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private static webView.hashUrl getSearchPath(string name)
        {
            return dataAccess.searchItem.GetSearchPath(include.search.FormatKey(name), dataAccess.search.type.Topic);
        }
    }
}
